unit UnitEdit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Spin, Mask, jpeg, ExtCtrls;

type
  TEditi = class(TForm)
    SpinEdit2: TSpinEdit;
    SpinEdit3: TSpinEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    ComboBox1: TComboBox;
    Label5: TLabel;
    MaskEdit3: TMaskEdit;
    Edit1: TEdit;
    Image1: TImage;
    procedure ADDstrin(Sender:TObject);
    procedure EditString(Sender: TObject;Sx:integer);
    procedure FormShow(Sender: TObject);
    procedure Image1MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Image1Click(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Editi: TEditi;

implementation

uses Unit1;

{$R *.dfm}






procedure TEditi.EditString(Sender: TObject;Sx:integer);
var h,i:integer;
begin


case Sx of
1:begin
h:=0;
for i:=0 to Form1.stringgrid1.ColCount-2 do  {f}
begin
h:=h+1;
(findcomponent(format('SpinEdit%d',[h])) as TSpinEdit).Text:=Form1.stringgrid1.Cells[i,Form1.Yc];
end;   {f}
end;
2:begin
h:=0;
for i:=0 to Form1.stringgrid1.ColCount-2 do  {f}
begin
h:=h+1;
Form1.stringgrid1.Cells[i,Form1.Yc]:=(findcomponent(format('SpinEdit%d',[h])) as TSpinEdit).Text;
end;   {f}

end;

end;


end;



procedure TEditi.ADDstrin(Sender:Tobject);
var i,col,h:integer;
en:integer;
s:string;
begin

h:=0;
col:=Form1.stringgrid1.RowCount-1;

en:=0;

{for i:=0 to Form1.stringgrid1.ColCount-2 do
begin
s:=Form1.stringgrid1.Cells[i,1];
if s<>'' then
begin
en:=1;
end;
end; }

if en=1 then begin      {Если первая строка непуста}
Form1.stringgrid1.RowCount:=Form1.stringgrid1.RowCount+1;
end;

for i:=0 to Form1.stringgrid1.ColCount-2 do  {f}
begin
h:=h+1;
Form1.stringgrid1.Cells[i,col]:=(findcomponent(format('SpinEdit%d',[h])) as TSpinEdit).Text;
end;   {f}

end;

procedure TEditi.FormShow(Sender: TObject);
begin
Edit1.Text:='';
MaskEdit3.Text:='';
SpinEdit2.Text:='0';
SpinEdit3.Text:='0';
Combobox1.Text:='';

if Editi.Caption='Редактирование абонента' then
begin
Form1.PoiskSapis(Sender,Form1.selsap);
{EditString(Sender,1); }
end;
end;

procedure TEditi.Image1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
image1.Picture.LoadFromFile('image\button2.jpg');
end;

procedure TEditi.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
image1.Picture.LoadFromFile('image\button2.jpg');
end;

procedure TEditi.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
image1.Picture.LoadFromFile('image\button3.jpg');

end;

procedure TEditi.Image1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
image1.Picture.LoadFromFile('image\button4.jpg');
end;

procedure TEditi.Image1Click(Sender: TObject);
begin
if Editi.Caption='Новый абонент' then
begin
{Form1.SaveFale(Sender);}
{ADDStrin(Sender); }
if not(FileExists('abonent'))  then
begin
Form1.SAve(Sender,2);
end
else begin Form1.Addsapis(Sender); end;

Form1.Sagruska(Sender,2);

end;

if Editi.Caption='Редактирование абонента' then
begin
{EditString(Sender,2);
Form1.SaveFale(Sender); }
Form1.EditSapis(Sender);
Form1.Sagruska(Sender,2);
end;

Form1.Raschet(Sender);


Close;
end;

end.
